Page({
  data: {
   cateItems: [
    {
     cate_id: 1,
     cate_name: "茶叶",
     ishaveChild: true,
     children:
     [
      {
       child_id: 1,
       name: '广西六堡茶',
       price:100,
       num:0,
       image: 'https://bkimg.cdn.bcebos.com/pic/279759ee3d6d55fb266cd48c67224f4a21a4ddf6?x-bce-process=image/watermark,image_d2F0ZXIvYmFpa2U5Mg==,g_7,xp_5,yp_5'
      },
      {
       child_id: 2,
       name: '忻城金银花',
       price:200,
       num:0,
       image: "https://bkimg.cdn.bcebos.com/pic/8ad4b31c8701a18bd95b8e79932f07082838fe50?x-bce-process=image/watermark,image_d2F0ZXIvYmFpa2UxMTY=,g_7,xp_5,yp_5"
      },
      {
       child_id: 3,
       name: '大新苦丁茶',
       price:100,
       num:0,
       image: "https://bkimg.cdn.bcebos.com/pic/7acb0a46f21fbe09ab0c8fee67600c338644adfe?x-bce-process=image/watermark,image_d2F0ZXIvYmFpa2U4MA==,g_7,xp_5,yp_5"
      },
      {
       child_id: 4,
       name: '防城金花茶',
       price:200,
       num:0,
       image: "https://bkimg.cdn.bcebos.com/pic/908fa0ec08fa513d16d6aa79336d55fbb2fbd91d?x-bce-process=image/watermark,image_d2F0ZXIvYmFpa2UxNTA=,g_7,xp_5,yp_5"
      },
      {
       child_id: 5,
       name: '西山茶',
       price:100,
       num:0,
       image: "https://bkimg.cdn.bcebos.com/pic/728da9773912b31bbb1f06228618367adab4e14e?x-bce-process=image/resize,m_lfit,w_268,limit_1"
      },
      {
       child_id: 6,
       name: '昭平茶',
       price:200,
       num:0,
       image: "https://bkimg.cdn.bcebos.com/pic/0823dd54564e92582d512f3c9082d158cdbf4eff?x-bce-process=image/watermark,image_d2F0ZXIvYmFpa2UyNzI=,g_7,xp_5,yp_5"
      },
      {
        child_id: 7,
        name: '龙州乌龙茶',
        price:100,
        num:0,
        image: 'https://bkimg.cdn.bcebos.com/pic/adaf2edda3cc7cd994da52e23401213fb80e9111?x-bce-process=image/watermark,image_d2F0ZXIvYmFpa2UyNzI=,g_7,xp_5,yp_5'
      }
     ]
    },
    {
     cate_id: 2,
     cate_name: "茶具",
     ishaveChild: true,
     children:
     [
      {
       child_id: 1,
       name: '紫砂茶具套装',
       price:300,
       num:0,
       image: "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg13.360buyimg.com%2Fn1%2Fjfs%2Ft3265%2F78%2F6315194648%2F467114%2F158d63eb%2F58a3d02aN2979d385.jpg&refer=http%3A%2F%2Fimg13.360buyimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1674390795&t=72e3a6834638054f3531ffefcf2b2006"
      },
      {
       child_id: 2,
       name: '小清新茶具',
       price:300,
       num:0,
       image: "https://img0.baidu.com/it/u=4075195922,2966974022&fm=253&fmt=auto&app=138&f=JPEG?w=561&h=500"
      },
      {
       child_id: 3,
       name: '精美陶瓷茶具',
       price:200,
       num:0,
       image: "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic1.win4000.com%2Fwallpaper%2F9%2F5387f95122404.jpg&refer=http%3A%2F%2Fpic1.win4000.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1674390795&t=d050ca1469169e684bd5dfd3c66fb41e"
      },
      {
       child_id: 4,
       name: '古韵功夫茶具',
       price:300,
       num:0,
       image: "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimgservice.suning.cn%2Fuimg1%2Fb2c%2Fimage%2FuANujinbg847AT03uW7_tA.jpg_800w_800h_4e&refer=http%3A%2F%2Fimgservice.suning.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1674390795&t=2ea8adcf5e5965db3aa5f2c55b34e027"
      },
      {
       child_id: 5,
       name: '景德镇陶瓷茶具',
       price:300,
       num:0,
       image: "https://img14.360buyimg.com/pop/jfs/t1/151449/13/19907/409695/603a8183Efe81bb37/7716d08aec6a00f3.jpg"
      },
      {
       child_id: 6,
       name: '舌灿莲花紫砂壶套装',
       price:200,
       num:0,
       image: "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fassets.puxiang.com%2Fuploads%2Fphoto%2Fimage%2F2045872%2F1d7aeedfbe07c125bad5eba2d2dba421.jpg&refer=http%3A%2F%2Fassets.puxiang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1674390795&t=a6648e340357fcf868890e25dd7178af"
      },
      {
       child_id: 7,
       name: '紫砂茶壶单壶',
       price:200,
       num:0,
       image: "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimgservice.suning.cn%2Fuimg1%2Fb2c%2Fimage%2FObS4en8VW28zuyq7-vCKqg.jpg_800w_800h_4e&refer=http%3A%2F%2Fimgservice.suning.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1674390795&t=56eb0dd11ec02551a0453f4e207d05de"
      }
     ]
    }
   ],
   curNav: 1,
   curIndex: 0
  },
  
  //事件处理函数 
  switchRightTab: function (e) {
   // 获取item项的id，和数组的下标值 
   let id = e.target.dataset.id,
    index = parseInt(e.target.dataset.index);
   // 把点击到的某一项，设为当前index 
   this.setData({
    curNav: id,
    curIndex: index
   })
  },
  addCount1(e){
    const index = e.currentTarget.dataset.index;
    let carts = this.data.cateItems;
    let num = carts[0].children[index].num;
    num +=1;
    carts[0].children[index].num = num;
    this.setData({
      cateItems:carts
    })
  },
  addCount2(e){
    const index = e.currentTarget.dataset.index;
    let carts = this.data.cateItems;
    let num = carts[1].children[index].num;
    num +=1;
    carts[1].children[index].num = num;
    this.setData({
      cateItems:carts
    })
  },
  reduceCount1(e){
    const index = e.currentTarget.dataset.index;
    let carts = this.data.cateItems;
    let num = carts[0].children[index].num;
    if(num <=0){
      return false
    }
    num = num -1;
    carts[0].children[index].num = num;
    this.setData({
      cateItems:carts
    })
  },
  reduceCount2(e){
    const index = e.currentTarget.dataset.index;
    let carts = this.data.cateItems;
    let num = carts[1].children[index].num;
    if(num <=0){
      return false
    }
    num = num -1;
    carts[1].children[index].num = num;
    this.setData({
      cateItems:carts
    })
  },
  })
  
  